#!/usr/bin/python

import math

def getHexCode(x):
    i = int(math.floor(x))
    f = int(math.floor(((x - i)) * 2**16))

    f = hex(f)[2:]
    f = "0"*(4 - len(f)) + f
    return hex(i) + f

startcode = """
#include "fixed.h"

int32_t Fixed_sintable16[] = {
"""

endcode = """
};
"""

fp = open("src/sintable.c", "w")
fp.write(startcode)

f = 0
i = 0
while i <= 320:
    print i, f, math.pi / 2, math.sin(f), (i * math.pi)/640, i * (math.pi/640)
    fp.write("    (int32_t)%s,\n" % (getHexCode(math.sin(f)), ))

    i += 1
    f = (i * math.pi)/640

fp.write(endcode)

fp.close()
